package io.renren.modules.generator.controller;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.generator.entity.AnimalpriceEntity;
import io.renren.modules.generator.service.AnimalpriceService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.common.utils.R;




/**
 * 
 * 
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2018-04-15 14:04:02
 */
@RestController
@RequestMapping("animalprice")
public class AnimalpriceController {
	@Autowired
	private AnimalpriceService animalpriceService;
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("animalprice:list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);

		List<AnimalpriceEntity> animalpriceList = animalpriceService.queryList(query);
		int total = animalpriceService.queryTotal(query);
		
		PageUtils pageUtil = new PageUtils(animalpriceList, total, query.getLimit(), query.getPage());
		
		return R.ok().put("page", pageUtil);
	}
	
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	@RequiresPermissions("animalprice:info")
	public R info(@PathVariable("id") Integer id){
		AnimalpriceEntity animalprice = animalpriceService.queryObject(id);
		
		return R.ok().put("animalprice", animalprice);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	@RequiresPermissions("animalprice:save")
	public R save(@RequestBody AnimalpriceEntity animalprice){
		animalpriceService.save(animalprice);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("animalprice:update")
	public R update(@RequestBody AnimalpriceEntity animalprice){
		animalpriceService.update(animalprice);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("animalprice:delete")
	public R delete(@RequestBody Integer[] ids){
		animalpriceService.deleteBatch(ids);
		
		return R.ok();
	}
	@RequestMapping("/timelist")
	@RequiresPermissions("animalprice:list")
	public R timelist(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);

		List<AnimalpriceEntity> animalpriceList = animalpriceService.timeList(query);
		int total = animalpriceService.timeTotal(query);
		
		PageUtils pageUtil = new PageUtils(animalpriceList, total, query.getLimit(), query.getPage());
		
		return R.ok().put("page", pageUtil);
	}
	
}
